# 字典   很像json
# 作用相当于   HashMap的键值对  有映射关系
a = {'color': 'green', 'num': '5'}
print(a['color'])
print(a['num'])

# 添加键值对
a['x_pointer'] = 0
a['y_pointer'] = 25
print(a)

# 空字典
b = {}

# 删除键值对
del a['num']

# ------------------- 遍历字典      ---------------
user = {
    'username': 'junhao',
    'sex': 'nan',
    'age': 2333,
    'wife': {
        'age': 22,
        'hobby':["唱歌","跳舞"]
    }
}

# 取值 跳舞
print(user['wife']['hobby'][1])

# 遍历键值对
for key, value in user.items():
    print('\nkey: ', key)
    print('value: ', value)

# 遍历字典的键
for name in user.keys():
    print(name)


'''
习题 分类  大于50的放一起  小于50的 ...   新建个list存
'''
lst = [11,22,33,44,55,66,77,88,99]
result ={}

for item in lst:
    if item > 50:
        if result.get("big") == None:   #没有big，创建一个列表 扔进去
            result['big'] = [item]
        else:
            result['big'].append(item)
    else:
        if result.get("small") == None:
            result['small'] = [item]
        else:
            result['small'].append(item)
# 这个是优化后的样子
# for item in lst:
#     if item > 50:
#         result.setdefault("big",[]).append(item)
#     else:
#         result.setdefault("small",[]).append(item)
print(result)
